package dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import entity.User;
import util.DBHelp;
import util.RowMapper;

public class UserDao{
	private DBHelp<User> db=new DBHelp<User>();
	
	public User findByUserName(String username){
		String sql="SELECT id,username,`password`,pic FROM t_user WHERE username=?";
		return db.executeQueryToObject(sql,new UserRowMapper(),username);
	}
	

/*	public void update(User user){
		String sql="update t_user set username=? ";
	}*/
	public class UserRowMapper implements RowMapper<User>{
		 
		public User mapRow(ResultSet rs) throws SQLException {
			User user=new User();
			
			
			user.setId(rs.getString("id"));
			user.setUsername(rs.getString("username"));
			user.setPassword(rs.getString("password"));
			user.setPic(rs.getString("pic"));
			return user;
		
			
		}

		
	}



	public List<User> findAll() {
		String sql="SELECT id,username,`password`,pic FROM t_user ";
		return db.executeQueryToList(sql,new UserRowMapper() );
	}
}
